#include<bits/stdc++.h>
using namespace std;
#define int long long

int a[100005];
int m, n;

bool check(int x) {
	int cnt = 1, t = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] > x)
			return false;
		t += a[i];
		if (t > x) {
			cnt++;
			t = a[i];
		}
	}
//	cout<<cnt<<endl;
	if (cnt > m)
		return false;
	else
		return true;
}

signed main() {
	cin >> n >> m;

	int l = -1, r = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		l = max(l, a[i]);
		r += a[i];
	}
	int mid, ans;
	while (l <= r) {
		mid = l + (r - l) / 2;
		cout << "l: " << l << " r: " << r << " mid: " << mid << " ch: " << check(mid) << endl;
		if (check(mid)) {
			ans = mid;
			r = mid - 1;
		} else {
			l = mid + 1;
		}
	}
	cout << ans;
	return 0;
}
